﻿/*
    基金管理员部门组
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace Benefit.Service.Sys
{
    /// <summary>
    /// 用户组表(需要)
    /// </summary>
    public class ServiceGroups : Benefit.Interface.Sys.IGroups
    {
        Benefit.DB.DBManager db = null;
        public ServiceGroups(Benefit.DB.DBManager db)
        {
            this.db = db;
        }
        /// <summary>
        /// 增加一个小组，默认没有子小组
        /// </summary>
        /// <returns></returns>
        public int AddGroup(string groupName,int parentGroupId)
        {
            Models.Sys.Groups g = new Models.Sys.Groups();
            g.GroupName = groupName;
            g.HasChildren = false;
            g.ParentGroupId = parentGroupId;
            g.IsDeleted = false;
            var query = db.Groups.Where(a => a.Id == g.ParentGroupId);
            if (query.Count() > 0)
            {
                Models.Sys.Groups group = query.First();
                group.HasChildren = true;
            }
            db.Groups.Add(g);
            db.SaveChanges();
            return g.Id;
        }

        public List<Models.Sys.Groups> GetGroups()
        {
            var query = db.Groups.Where(a => a.IsDeleted == false).ToList();
            return query;
        }

        /// <summary>
        /// 得到交易员可以看到的小组的列表
        /// </summary>
        /// <param name="operatorid"></param>
        /// <returns></returns>
        public List<Models.Sys.Groups> GetOperatorCouldSeeGroups(int operatorid)
        {
            List<Models.Sys.Groups> groups = new List<Models.Sys.Groups>();

            return groups;
        }

        public Models.Sys.Groups GetGroup(int id)
        {
            return db.Groups.Find(id);
        }
    }
}